package com.example.smart.ui.activity.today_circle

import com.example.lib.constants.JumpConstants
import com.example.lib.extend.dip2px
import com.example.lib.extend.getIntentInt
import com.example.lib.extend.gone
import com.example.lib.extend.setMargin
import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.extend.setWidthOrHeightNot2Px
import com.example.lib.extend.verticalManager
import com.example.lib.utils.sp.SpUtils
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.adapter.home.CommandAdapter
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.data.CommandData
import com.example.smart.databinding.ActivityToadyCircleDetailsBinding
import com.example.smart.dialog.CommandDialog

class TodayCircleDetailsActivity : BaseActivity<ActivityToadyCircleDetailsBinding>() {
    private var flag = false
    private var type = 0
    private val mAdapter by lazy {
        CommandAdapter(this@TodayCircleDetailsActivity)
    }

    private val mDialog by lazy {
        CommandDialog(this@TodayCircleDetailsActivity)
    }

    override fun layoutID() = R.layout.activity_toady_circle_details

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@TodayCircleDetailsActivity,
            statusBarColor = com.example.lib.R.color.white)

        type = getIntentInt(JumpConstants.ID)
        val data = mutableListOf<CommandData>()
        if (type == 1) {
            flag = SpUtils.getBoolean("gz1", false)
            data.add(CommandData(R.mipmap.icon_photo9,
                "草原老张",
                "3h",
                "先灌半支葡萄糖酸钙，再用热盐袋敷后腿，晚上注意保暖。我家去年也这样，三天后能踉跄走了。",
                12,
                1))

            data.add(CommandData(R.mipmap.icon_photo10,
                "乌云其其格",
                "3h",
                "可能是缺硒，我们这叫“白肌病”，赶紧找兽医打亚硒酸钠！晚了肌肉就萎缩了……",
                6,
                2))

        } else {
            flag = SpUtils.getBoolean("gz2", false)
            binding.Image1.setImageResource(R.mipmap.icon_photo8)
            binding.Text1.text = getString(R.string.today_msg11)
            binding.Text2.text = getString(R.string.today_msg12)
            binding.Image2.setImageResource(R.mipmap.icon_back11)
            binding.Text6.text = getString(R.string.today_msg14)
            binding.Text4.gone()
            binding.Text6.setBackgroundResource(com.example.lib.R.drawable.shape_25_9dd030_solid)
            binding.Text1.setCompoundDrawables(null, null, null, null)
            binding.Text5.setMargin(top = dip2px(10f))
            data.add(CommandData(R.mipmap.icon_photo9, "草原老张", "3h", "非常有用的帖子！收藏了！", 12, 1))
        }

        binding.Text7.text = String.format(getString(R.string.today_msg16), data.size)

        if (flag) {
            binding.Text3.text = "已关注"
        } else {
            binding.Text3.text = "关注"
        }

        binding.Recycler.verticalManager()
        binding.Recycler.adapter = mAdapter
        mAdapter.updateList(data)
    }

    override fun initListener() {
        binding.Post.setOnDoubleClickListener {
            mDialog.show()
        }

        binding.Text3.setOnDoubleClickListener {
            flag = !flag
            SpUtils.putBoolean("gz${type}", flag)
            if (flag) {
                binding.Text3.text = "已关注"
            } else {
                binding.Text3.text = "关注"
            }
        }

        mAdapter.onHeight = {
            binding.Recycler.setWidthOrHeightNot2Px(height = it * mAdapter.size())
        }
    }

}